<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "110px"
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    };
  },
  watch: {
    // chartData: {
    //   deep: true,
    //   handler(val) {
    //     this.setOptions(val);
    //   }
    // }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.setOptions(this.chartData);
    },
    setOptions({ DayData } = {}) {
      this.chart.setOption({
        xAxis: {
          type: "category",
          data: [
            "0h",
            "1h",
            "2h",
            "3h",
            "4h",
            "5h",
            "6h",
            "7h",
            "8h",
            "9h",
            "10h",
            "11h",
            "12h",
            "13h",
            "14h",
            "15h",
            "16h",
            "17h",
            "18h",
            "19h",
            "20h",
            "21h",
            "22h",
            "23h"
          ],
          axisLine: {
            lineStyle: {
              type: "solid",
              color: "#b3b3b3", //左边线的颜色
              width: "2" //坐标线的宽度
            }
          }
        },
        visualMap: {
          show: false,
          min: 0,
          max: 50,
          dimension: 0,
          inRange: {
            color: ["#308e92", "#f5d69f"]
          }
        },
        yAxis: {
          type: "value",
          axisLine: {
            show: false, //设置y坐标隐藏
            lineStyle: {
              type: "solid",
              color: "#b3b3b3", //左边线的颜色
              width: "2" //坐标线的宽度
            }
          }
        },
        series: [
          {
            data: [30, 36, 38, 34, 39, 40, 44, 41, 48, 43, 40, 37, 36, 38, 34, 39, 40, 44, 41,35,32,30],
            type: "bar",
            barWidth: 5,
            barGap: "50%" /*多个并排柱子设置柱子之间的间距*/
          }
        ],
        grid: {
          // 设置图表的位置
          left: 10,
          right: 10,
          bottom: 0,
          top: 25,
          containLabel: true
        }
      });
    }
  }
};
</script>